﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using StillVoiceCommon;
using TN5Y.Server;
using TN5Y;
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;
using System.Text;
using System.Collections.Generic;
using System.IO;
/// <summary>
/// Summary description for StaffMember
/// </summary>
namespace TeamTime.Classes
{
    public class Invitation : StillVoiceCommon.DataTableRow
    {
        #region properties

        private string usernameModifiedBy;

        public new string UserNameModifiedBy
        {
            get { return usernameModifiedBy; }
            set { usernameModifiedBy = value; }
        }
        #endregion
        public Invitation()
        {
            this.initClass(TN5Y.Utilities.DBConnectionString, "Events.EventPerson");
        }
        public new void load(string id)
        {
            base.load(id);
            System.Data.SqlClient.SqlDataReader dr = SqlHelper.ExecuteReader(TN5Y.Utilities.DBConnectionString, CommandType.Text,
                "select * from Events.Event where ID = " + @id,
                new SqlParameter("id", id));
            if (dr.Read())
            {
                usernameModifiedBy = dr["UserIDModifiedBy"].ToString();

            }
            dr.Close();
            dr = null;
        }
    }
    public class Invitations
    {
        public DataSet searchInvitedPersons(string searchFor, string sortExpression)
        {
            StringBuilder sql = new StringBuilder("SELECT * FROM ViewEventPerson where 1=1 ");
            if (searchFor != "")
            {
                sql.Append(" and (FullName like '%'+@searchFor+'%' or");
                sql.Append(" EventName like '%'+@searchFor+'%' ");
                sql.Append(" EventType like '%'+@searchFor+'%' ");

                sql.Append(") ");
            }

            if (sortExpression != "")
            {
                sql.Append(" order by " + sortExpression);
            }
            return SqlHelper.ExecuteDataset(TN5Y.Utilities.DBConnectionString, CommandType.Text, sql.ToString(),
                                                new SqlParameter("searchFor", searchFor));
        }
        public int GetProvinceIDFromName(string ProvinceName)
        {
            int ret = -1;
            string sql = "select ID from Province where Description Like '"+ProvinceName+"'";

            SqlDataReader dr;
            dr = SqlHelper.ExecuteReader(TN5Y.Utilities.DBConnectionString, CommandType.Text, sql,
                new SqlParameter("Description", ProvinceName));
            if (dr.Read())
            {
                ret = Convert.ToInt32(dr[0].ToString());
            }
            dr.Close();
            return ret;
        }
    }
}
